package bishi.alibaba;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @Info:
 * @Author: Tangxz
 * @Date: 2020/09/06 20:00
 */
public class _42 {
    public static void main(String[] args) throws IOException {
        BufferedReader readTxt = new BufferedReader(new FileReader(new File("C:\\Users\\Administrator\\Desktop\\面试、算法\\src\\bishi.alibaba\\_42.txt")));
        String textLine = "";

        String str = "";

        while ((textLine = readTxt.readLine()) != null) {
            str += " " + textLine;
        }
        String[] numbersArray = str.replace(" ","").split(",");//这个逗号bai还可以是其他的字符
        int[] nums = new int[100000];
        for (int i=0;i<numbersArray.length;i++){
            nums[i] = Integer.parseInt(numbersArray[i]);
        }

        System.out.println(solution(100000,nums));//
    }
    public static int solution(int n,int[] nums) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int num:nums){
            set1.add(num);
        }
        set1.forEach(System.out::println);
        while (set1.size()>1) {
            int min = Collections.min(set1);
            Set<Integer> finalSet = set2;
            finalSet.add(min);
            set1.forEach((num) -> {
                if (num != min && num% min!=0) {
                    finalSet.add(num%min);
                }
            });
            set1 = set2;
            set1.forEach(System.out::println);
            System.out.println("-------------");
            set2 = new HashSet<>();
        }
        return Collections.max(set1);
    }
}